<template>
	<div id="evaluate" style="height: 100%;">
		<header id="header" class="mui-bar mui-bar-nav">
			<a class="mui-icon mui-icon-left-nav mui-pull-left" @click="goBack"></a>
			<h1 class="mui-title">{{title}}<span></span><span style="display: none;"><a class="mui-icon mui-icon-arrowdown"></a></span></h1>
			<a class="mui-btn mui-btn-blue mui-btn-link mui-pull-right" @click="sort()"><img width="25" height="25" style="margin-top: 7px;" src="../../../static/img/a1.png" /></a>
		</header>
		<div class="mui-content" v-if="!noData">
			<p class=" artinfo" v-for="item in items" @click="detailList(item.Num,item.Name)"><span>{{item.Name}}</span><span class="average">{{item.Score}}</span><span class="mui-icon mui-icon-arrowright"></span></p>
		</div>
		<div v-if="noData" class="noData">
			<img src="../../../static/img/暂无记录@2x.png" alt="" width="200" height="200" />
		</div>
	</div>
</template>

<script>
	import axios from 'axios'
	import {
		saveToLocal,
		loadFromLocal
	} from '@/service/store';
	export default {
		data() {
			return {
				title: "",
				ClassID: "",
				items: [],
				type: "",
				orderBy: "DESC",
				noData: false,
				UserInfo: loadFromLocal("userInfo", "obj"),
				SemesterCode: ""
			}
		},
		created() {
			let self = this;
			self.title = self.$route.params.ClassName;
			self.ClassID = self.$route.params.ClassID;
			self.type = self.$route.params.type;
			self.SemesterCode = self.$route.params.semesterCode;
			//			debugger
			if(self.type == 1) {
				axios({
					url: window.host + '/StatisticService/GetAverageScoreForAll',
					method: 'post',
					data: {
						BH: self.ClassID,
						type: 1,
						orderBy: 'DESC',
						SemesterCode: self.SemesterCode
					},
					transformRequest: [function(data) {
						// Do whatever you want to transform the data
						let ret = ''
						for(let it in data) {
							ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
						}
						return ret
					}]
				}).then((res) => {
					//					console.log(res.data);
					if(res.data.data) {
						if(res.data.data.resultlist.length !== 0) {
							self.items = res.data.data.resultlist;
						} else {
							self.items = []
							self.noData = true;
						}
					} else {
						self.items = []
						self.noData = true;
					}
					//					console.log(self.studentOrders)
					//					console.log(self.studentOrders[0].XM)
				});
			} else if(self.type == 2) {
				//获取班级内学生
				//				debugger
				axios({
					url: window.host + '/StatisticService/GetAverageScoreForAll',
					method: 'post',
					data: {
						ZYDM: self.ClassID,
						type: 2,
						orderBy: 'DESC',
						SemesterCode: self.SemesterCode
					},
					transformRequest: [function(data) {
						// Do whatever you want to transform the data
						let ret = ''
						for(let it in data) {
							ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
						}
						return ret
					}]
				}).then((res) => {
					//					console.log(res.data);
					if(res.data.data) {
						if(res.data.data.resultlist.length !== 0) {
							self.items = res.data.data.resultlist;
						} else {
							self.items = []
							self.noData = true;
						}
					}
					//					console.log(self.studentOrders)
					//					console.log(self.studentOrders[0].XM)
				});
			} else if(self.type == 3) {
				axios({
					url: window.host + '/StatisticService/GetAverageScoreForAll',
					method: 'post',
					data: {
						type: 3,
						orderBy: 'DESC',
						SemesterCode: self.SemesterCode
					},
					transformRequest: [function(data) {
						// Do whatever you want to transform the data
						let ret = ''
						for(let it in data) {
							ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
						}
						return ret
					}]
				}).then((res) => {
					//					console.log(res.data);
					if(res.data.data) {
						if(res.data.data.resultlist.length !== 0) {
							self.items = res.data.data.resultlist;
						}
					} else {
						self.items = []
						self.noData = true;
					}
					//					console.log(self.studentOrders)
					//					console.log(self.studentOrders[0].XM)
				});
			}

		},
		methods: {
			//正反排序
			sort() {
				let self = this;

				if(self.orderBy == "DESC") {
					self.orderBy = "ASC"
				} else {
					self.orderBy = "DESC"
				}
				if(self.type == 1) {
					axios({
						url: window.host + '/StatisticService/GetAverageScoreForAll',
						method: 'post',
						data: {
							BH: self.ClassID,
							type: 1,
							orderBy: self.orderBy
						},
						transformRequest: [function(data) {
							// Do whatever you want to transform the data
							let ret = ''
							for(let it in data) {
								ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
							}
							return ret
						}]
					}).then((res) => {
						//						console.log(res.data);
						self.items = res.data.data.resultlist;
						//					console.log(self.studentOrders)
						//					console.log(self.studentOrders[0].XM)
					});
				} else if(self.type == 2) {
					axios({
						url: window.host + '/StatisticService/GetAverageScoreForAll',
						method: 'post',
						data: {
							ZYDM: self.ClassID,
							type: 2,
							orderBy: self.orderBy
						},
						transformRequest: [function(data) {
							// Do whatever you want to transform the data
							let ret = ''
							for(let it in data) {
								ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
							}
							return ret
						}]
					}).then((res) => {
						//						console.log(res.data);
						self.items = res.data.data.resultlist;
						//					console.log(self.studentOrders)
						//					console.log(self.studentOrders[0].XM)
					});
				} else if(self.type == 3) {
					axios({
						url: window.host + '/StatisticService/GetAverageScoreForAll',
						method: 'post',
						data: {
							type: 3,
							orderBy: self.orderBy
						},
						transformRequest: [function(data) {
							// Do whatever you want to transform the data
							let ret = ''
							for(let it in data) {
								ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
							}
							return ret
						}]
					}).then((res) => {
						//						console.log(res.data);
						self.items = res.data.data.resultlist;
						//					console.log(self.studentOrders)
						//					console.log(self.studentOrders[0].XM)
					});
				}

			},
			//行为分析个人
			detailList(id, name) {
				let self = this;
				//学生列表
				if(self.type == 1) {
					self.$router.push({
						name: "EvaluateDetailPerson",
						params: {
							id: id,
							name: name
						}
					})
				} else if(self.type == 2) {
					//班级列表
					saveToLocal("skipInfob", {
						ClassID: id,
						Name: name,
					})
					self.$router.push({
						name: "EvaluateDetailTeacher",
						params: {
							UserID: self.UserInfo.UserID,
							type: 3,
							num: 1
						}
					})
				} else if(self.type == 3) {
					//专业列表 不会出现
					saveToLocal("skipInfoa", {
						ClassID: id,
						Name: name
					})
					self.$router.push({
						name: "EvaluateDetailProfession",
						params: {
							UserID: self.UserInfo.UserID,
							type: 5,
							num: 1
						}
					})
				}
			}
		}
	}
</script>

<style scoped>
	.noData {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100%;
	}
</style>